#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
/*
MainWindow::MainWindow(AppConfig& config, Users& users, QWidget *parent) :
    QMainWindow(parent), ui(new Ui::MainWindow), conf(config), usrs(users)
{
    ui->setupUi(this);

    applyConfig();

    connect(this, SIGNAL(addUser(QString)), &usrs, SLOT(addUser(QString)));
    connect(&usrs, SIGNAL(userAdded(QString)), &model_, SLOT(addUser(QString)));

    connect(ui->scheduleTable, SIGNAL(clicked(QModelIndex)),
        &model_, SLOT(switchShiftType(QModelIndex)));

    connect(ui->scheduleSwitcher, SIGNAL(dateChanged(QDate)),
        &model_, SLOT(loadSchedule(QDate)));

    ui->scheduleTable->setModel(&model_);

    model_.loadSchedule(conf.getLastUsedSchedule());

    loadUsers();
}
*/
MainWindow::~MainWindow()
{
    QSize winSize = size();
    conf.setWinWidth(winSize.width());
    conf.setWinHeigth(winSize.height());
    conf.setLastUsedSchedule(ui->scheduleSwitcher->date());

    ui->scheduleTable->setModel(NULL);

    delete ui;
}

void MainWindow::applyConfig() {
    resize(conf.getWinWidth(), conf.getWinHeigth());
    ui->scheduleSwitcher->setDate(conf.getLastUsedSchedule());
}

void MainWindow::loadUsers() {
    /*foreach(QString user, usrs.getUsers()) {
        model_.addUser(user);
    }*/
}

void MainWindow::on_actionOpen_triggered()
{

}

void MainWindow::on_actionAddAllUsers_triggered()
{

}

void MainWindow::on_addUser_clicked()
{
    QString name = ui->userName->text();
    if(!name.trimmed().isEmpty()) {
        emit addUser(name.trimmed());
    } else {
        //TODO error
    }
}
